package uk.co.q3c.deplan.server.rcp.model;

import java.util.logging.Level;
import java.util.logging.Logger;

import uk.co.q3c.deplan.client.domain.PropertyChangeEvent;
import uk.co.q3c.deplan.client.domain.PropertyChangeListener;

/**
 * Maintains a list of objects which are changed, to enable restoration of earlier values. Similar principle as an undo list, except that
 * values can be restored from any point in its history. Uses {@link ArrayList4} so that the list could be stored if so desired.
 * 
 * @author DSowerby 13 Apr 2009
 * 
 */
public class UndoRestoreList implements PropertyChangeListener {
	transient protected final Logger logger = Logger.getLogger(getClass().getName());

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		if (logger.isLoggable(Level.FINE)) {
			logger.fine("Undo list observing change to property '" + evt.getPropertyName() + "' in " + evt.getSource() + " from " + evt.getOldValue()
					+ " to " + evt.getNewValue());
		}

		// ignore calls to priority where old value < 0
		// these are provided for subTasks who have priority of 0
		// and may need to refresh display, but their persistent value doesn't
		// change
		if (evt.getPropertyName().equals("priority")) {
			int oldValue = (Integer) evt.getOldValue();
			if (oldValue < 0) {
				return;
			}
		}
	}

}
